layout (location = 0) out vec4 eceGlPosition;
layout (location = 1) out vec4 eceGlNormal;
layout (location = 2) out vec4 eceGlAlbedoSpec;
layout (location = 3) out vec4 eceGlGameData;

uniform ece_Material material;
uniform sampler2D texture;
uniform bool existTexture;
uniform sampler2D eceGlAlbedoSpecTexture;
varying vec2 vTexCoord;
varying vec3 vNormal;
varying vec3 vPosition;
varying vec4 vGlPosition;
varying float vDistance;
void main() {
	vec4 baseColor = existTexture ? texture2D(texture, vTexCoord) : vec4(1, 1, 1, 1);
	eceGlPosition.rgb = vPosition;
	eceGlPosition.a = vDistance;
	eceGlNormal.rgb = vNormal;
	eceGlNormal.a = material.enable ? material.shininess : 24;
	if(material.enable) {
		if(material.alpha < 1) {
			vec2 vGlTexCoord = (vGlPosition.xy / vGlPosition.w + 1) / 2;
			vec4 color = texture2D(eceGlAlbedoSpecTexture, vGlTexCoord);
			eceGlAlbedoSpec.rgb = mix(color.rgb, baseColor.rgb, material.alpha) * material.diffuse;
		} else {
			eceGlAlbedoSpec.rgb = baseColor.rgb * material.diffuse;
		}
		eceGlAlbedoSpec.a = material.specular.r;
	} else {
		eceGlAlbedoSpec.rgb = material.enable ? baseColor.rgb * material.diffuse : baseColor.rgb;
		eceGlAlbedoSpec.a = 0;
	}
	eceGlGameData.r = 0;
}